﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterALSafa.Master" AutoEventWireup="true"
    CodeBehind="PaymentOrderEditor.aspx.cs" Inherits="School.Pages.Accounting.PaymentOrderEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        $(document).ready(
            $('.AddVoucher a').live('click', function () {
                var currentTime = new Date();
                var voucherDate = prompt("برجاء ادخال التاريخ", currentTime.getFullYear().toString() + "-" + (currentTime.getMonth() + 1).toString() + "-" + currentTime.getDate());

                var value = parseFloat($(this).parent().parent().find('.VoucherValue').text());
                var ivalue = parseFloat(prompt("برجاء ادخال القيمة المدفوعة", value));

                if (ivalue.toString() == "NaN")
                    alert("برجاء ادخال قيمة صحيحة");
                else if (ivalue > value)
                    alert("القيمة التى ادخلتها اكبر من القيمة المطلوبة و هى : " + value);
                else {
                    if (isDate(voucherDate)) {
                        window.open($(this).attr("href") + "&Paid=" + ivalue.toString() + "&date=" + voucherDate, 'الإيصال', "status=1,height=500,width:500");
                        $(this).parent().html("دفع");
                    }
                    else
                        alert('برجاء ادخال تاريخ صحيح');
                }
                return false;
            }),

            $("")
        );

        function y2k(number) { return (number < 1000) ? number + 1900 : number; }

        function isDate(date) {
            var dateArray = date.split('-');

            if (dateArray.length != 3)
                return false;

            var year = dateArray[0];
            var month = dateArray[1];
            var day = dateArray[2];
            var today = new Date();
            year = ((!year) ? y2k(today.getYear()) : year);
            month = ((!month) ? today.getMonth() : month - 1);
            if (!day) return false
            var test = new Date(year, month, day);
            if ((y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()))
                return true;
            else
                return false
        }

    </script>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table width="100%">
                <tr>
                    <td style="width: 50%">
                        <table width="100%">
                            <tr>
                                <td width="40%">
                                    المجمع
                                </td>
                                <td>
                                    <asp:DropDownList ID="LstCampuses" runat="server" OnSelectedIndexChanged="LstCampuses_SelectedIndexChanged"
                                        AutoPostBack="True">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td width="40%">
                                    الشهادة
                                </td>
                                <td>
                                    <asp:DropDownList ID="LstCertificates" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LstCertificates_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td width="40%">
                                    المرحلة
                                </td>
                                <td>
                                    <asp:DropDownList ID="LstStages" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LstStages_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td width="40%">
                                    الصف
                                </td>
                                <td>
                                    <asp:DropDownList ID="LstGrades" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LstGrades_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td width="40%">
                                    الطالب
                                </td>
                                <td>
                                    <asp:DropDownList ID="LstStudents" runat="server" OnSelectedIndexChanged="LstStudents_SelectedIndexChanged"
                                        AutoPostBack="True">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    اسم الطالب
                                </td>
                                <td>
                                    <asp:TextBox ID="TxtStudentName" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    أو رقم الطالب
                                </td>
                                <td>
                                    <asp:TextBox ID="TxtStudentNumber" runat="server"></asp:TextBox>
                                </td>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="BtnSearch" runat="server" Text="بحث" OnClick="BtnSearch_Click" />
                    </td>
                </tr>
            </table>
            </td> </tr>
            <tr>
                <td colspan="2">
                    <asp:Panel CssClass="students_search_grid" ID="StudentsPanel" runat="server" Visible="false">
                        <h2>
                            الطلاب</h2>
                        <asp:GridView ID="StudentsGrid" runat="server" Width="100%" CssClass="Grid" HeaderStyle-CssClass="GridHeaderFooter"
                            FooterStyle-CssClass="GridHeaderFooter" PagerStyle-CssClass="GridPager" AlternatingRowStyle-CssClass="GridItemAltername"
                            AutoGenerateColumns="False" Visible="False" 
                            onrowcommand="StudentsGrid_RowCommand">
                            <AlternatingRowStyle CssClass="GridItemAltername" />
                            <Columns>
                                <asp:BoundField DataField="StudentNumber" HeaderText="رقم الطالب" />
                                <asp:BoundField DataField="StudentName" HeaderText="اسم الطالب" />
                                <asp:BoundField DataField="Certificate" HeaderText="القسم" />
                                <asp:BoundField DataField="Grade" HeaderText="الصف" />
                                <asp:TemplateField Visible="False">
                                    <ItemTemplate>
                                        <asp:Label ID="LblStudentId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:ButtonField ButtonType="Button" Text="اختيار" CommandName="Select" />
                            </Columns>
                            <FooterStyle CssClass="GridHeaderFooter" />
                            <HeaderStyle CssClass="GridHeaderFooter" />
                            <PagerStyle CssClass="GridPager" />
                        </asp:GridView>
                        <asp:Label Font-Size="Larger" ID="LblSearchNotFound" runat="server" Text="لم يتم العثور على الطالب"
                            ForeColor="Red" Visible="false"></asp:Label>
                    </asp:Panel>
                    <asp:HiddenField ID="HfStudentId" runat="server" OnValueChanged="HfStudentId_ValueChanged" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Panel ID="FinancePanel" runat="server" Visible="False">
                        <table style="width: 100%">
                            <tr>
                                <td style="width: 43%">
                                    نوع الإيراد
                                    <asp:DropDownList ID="LstExpenses" runat="server" OnSelectedIndexChanged="LstExpenses_SelectedIndexChanged"
                                        AutoPostBack="True">
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    الدفعة
                                    <asp:DropDownList ID="LstPayments" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LstPayments_SelectedIndexChanged">
                                    </asp:DropDownList>
                                    &nbsp;
                                    <asp:Label ID="LblPaymentValue" runat="server" Visible="False"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="height: 136px">
                                    <asp:GridView ID="GridView1" runat="server" Width="100%" CssClass="Grid" HeaderStyle-CssClass="GridHeaderFooter"
                                        FooterStyle-CssClass="GridHeaderFooter" PagerStyle-CssClass="GridPager" AlternatingRowStyle-CssClass="GridItemAltername"
                                        AutoGenerateColumns="False">
                                        <AlternatingRowStyle CssClass="GridItemAltername" />
                                        <Columns>
                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="ChkDiscount" runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="الخصم">
                                                <ItemTemplate>
                                                    <asp:Label ID="Name" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                                                    <asp:Label ID="LblDiscountId" Visible="false" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="النوع" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="Type" runat="server" Text='<%# GetType(Eval("Type")) %>'></asp:Label>
                                                    <asp:Label Visible="false" ID="LblType" runat="server" Text='<%# Eval("Type") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="القيمة">
                                                <ItemTemplate>
                                                    <asp:Label ID="Value" runat="server" Text='<%# GetValue(Eval("Type"),Eval("Value")) %>'></asp:Label>
                                                    <asp:Label Visible="false" ID="LblValue" runat="server" Text='<%# Eval("Value") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                        <FooterStyle CssClass="GridHeaderFooter" />
                                        <HeaderStyle CssClass="GridHeaderFooter" />
                                        <PagerStyle CssClass="GridPager" />
                                    </asp:GridView>
                                    <asp:Button ID="Button2" runat="server" Text="انشاء امر دفع" OnClick="Button2_Click" />
                                    <asp:Button ID="Button1" runat="server" Text="حساب المبلغ" OnClick="Button1_Click" />
                                    <asp:Label ID="Label1" runat="server" Text="القيمة النهائية : "></asp:Label>
                                    <asp:Label ID="LblFinalValue" runat="server" value="00.00"></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Panel ID="Panel1" runat="server" Visible="false" CssClass="payment-panel">
                        <asp:GridView ID="PaymentOrderGrid" runat="server" Width="100%" CssClass="Grid" HeaderStyle-CssClass="GridHeaderFooter"
                            FooterStyle-CssClass="GridHeaderFooter" PagerStyle-CssClass="GridPager" AlternatingRowStyle-CssClass="GridItemAltername"
                            AutoGenerateColumns="False" EnableViewState="False">
                            <AlternatingRowStyle CssClass="GridItemAltername" />
                            <Columns>
                                <asp:BoundField DataField="Student_Number" HeaderText="رقم الطالب" />
                                <asp:BoundField DataField="Student_Name" HeaderText="اسم الطالب" />
                                <asp:BoundField DataField="Number" HeaderText="رقم امر الدفع" />
                                <asp:BoundField DataField="Date" HeaderText="تاريخ أمر الدفع" />
                                <asp:BoundField DataField="Expense_Name" HeaderText="نوع الإيراد" />
                                <asp:BoundField DataField="Value" HeaderText="القيمة" ItemStyle-CssClass="VoucherValue" />
                                <asp:HyperLinkField DataNavigateUrlFields="Number" DataNavigateUrlFormatString="VoucherPayment.aspx?Number={0}"
                                    Text="دفع" Target="_blank" ItemStyle-CssClass="AddVoucher">
                                    <ItemStyle CssClass="AddVoucher" />
                                </asp:HyperLinkField>
                                <asp:HyperLinkField DataNavigateUrlFields="Number" DataNavigateUrlFormatString="PaymentOrderPrinting.aspx?Number={0}"
                                    Text="طباعة" Target="_blank"></asp:HyperLinkField>
                            </Columns>
                            <FooterStyle CssClass="GridHeaderFooter" />
                            <HeaderStyle CssClass="GridHeaderFooter" />
                            <PagerStyle CssClass="GridPager" />
                        </asp:GridView>
                    </asp:Panel>
                </td>
            </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
